<template>
  <el-dialog v-model="visibleForm" :title="`添加沟通内容`" width="460px" :close-on-click-modal="false"
    :close-on-press-escape="false" @close="close()">
    <el-form :model="formData" :rules="formRules" label-width="100px">
      <el-form-item label="沟通内容:" prop="visitInfo">
        <el-input type="textarea" v-model="formData.visitInfo" style="width:360px" clearable placeholder="请输入沟通"></el-input>
      </el-form-item>
      <el-form-item label="沟通时间:" prop="visitTime">
        <el-date-picker
          v-model="formData.visitTime"
          type="datetime"
          placeholder="填写沟通时间"
          style="width:260px"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" :disabled="isDisabled" @click="confirm()">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref,  defineProps, defineEmits,  toRefs, reactive, watch } from "vue";
import { custVisitAdd } from '../api.js'
import { ElMessage } from "element-plus";
import * as DeviceUtils from "../utils";

let props = defineProps({
  showDialog: Boolean,
  custom: Object
})

const {currentRow} = toRefs(props)


let visibleForm = ref(props.showDialog)
let emit = defineEmits(['close', 'success'])

const formData = reactive({
  visitInfo: '',
  visitTime: ''
});

const formRules = reactive({
  visitInfo: [
      { required: true, message: '请输入沟通内容', trigger: 'blur' },
  ],
  visitTime: [
      { required: true, message: '请输入沟通时间', trigger: 'blur' },
  ],
})

const close = () => {
  emit('close')
}
const confirm = async () => {
  submit()
}
const submit = async () => {
  let params = {
    custID: props.custom.custID,
    visitInfo: formData.visitInfo,
    visitTime: new Date(formData.visitTime).getTime()
  }
  const res = await custVisitAdd(params)
  if (0 === res.status) {
    ElMessage({
      message: '添加成功',
      type: "success",
      duration: 3000,
    })
    emit('success')
    emit('close')
  } else {
    ElMessage({
      showClose: true,
      message: res.message || '添加失败',
      type: "error",
    });
  }
}
</script>
<style lang="scss" scoped>
.desc {
  margin-bottom: 20px;
}
</style>